<?php

include_once(create_path("plugin/video/tpl_video.php"));
include_once(create_path("plugin/video/lg_video_".LANG.".php"));
include_once(create_path("plugin/video/sql_video.php"));

include(create_path("plugin/video/conf.php"));

/**
* return un tableau de video en embed et thumbnail
*/

function convertir_lien_en_miniature($lieen)
{
    if (preg_match("#youtube#", $lieen))
    {
        $miniature = str_replace('http://www.youtube.com/watch?v=', '', $lieen);
        echo 'http://img.youtube.com/vi/'. $miniature . '/default.jpg' ;
    }
    else
    {
        if (preg_match("#dailymotion#", $lieen))
        {
            $miniature = str_replace('http://www.dailymotion.com/video/', '', $lieen);
            echo 'http://www.dailymotion.com/thumbnail/150x120/video/'. $miniature . '' ;
         
        }
        else 
        {
         
            if (preg_match("#vimeo#", $lieen))
            {
                $miniature = str_replace('http://vimeo.com/', '', $lieen);
                $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$miniature.php"));
                echo $hash[0]['thumbnail_small'];
             
            }
            else {}
        }
    }
}

function getVideo ($_zUrl)
{
    $zCode = '' ;
    $zUrlEmbed = '' ;
    $zUrlThumb = '' ;
    $toReturns = false ;
    if (strstr($_zUrl, 'www.dailymotion.com')) 
    {
        $zCode =  preg_replace('#(.*)/video/([^_]*)_?.*#', '$2', $_zUrl) ;
        $zUrlEmbed = 'http://www.dailymotion.com/embed/video/' . $zCode ;
        $zUrlThumb = 'http://www.dailymotion.com/thumbnail/150x120/video/'. $zCode . '' ;
    }
    elseif (strstr($_zUrl, 'www.youtube.com'))
    {
        $zCode =  preg_replace('#(.*)v=([^&]*)&?.*#', '$2', $_zUrl) ;
        $zUrlEmbed = 'http://www.youtube.com/embed/' . $zCode ;
        $zUrlThumb = 'http://img.youtube.com/vi/'. $zCode . '/default.jpg' ;
    }
    
    if ($zUrlEmbed && $zUrlThumb)
    {
        $toReturns['embed'] = $zUrlEmbed ;
        $toReturns['thumb'] = $zUrlThumb ;
    }

    return $toReturns ;
}

# we check if the plugin is installed
if($plugin_install!=1) 
{
 include(create_path("plugin/video/install.php"));
}
else
{
 if(!isset($_GET['v1']))
 {
  include(create_path("plugin/video/video_list.php"));
 }
 else
 {
  switch($_GET['v1']) {
   case "form_video" :  include(create_path("plugin/video/form_video.php")); break;
   case "video_list" :  include(create_path("plugin/video/video_list.php")); break;
   case "view" : include(create_path("plugin/video/view_video.php")); break;
   default : include(create_path("plugin/video/video_list.php"));
  }
 }
}
?>